
const mysqlTool = require('./mysqlPool.js');

mysqlTool.executeSql ('SELECT *FROM user',function (err,result) {

    if (err)
    {
        console.log(err.message);
    }
    else
    {
        console.log('--------------------------SELECT----------------------------');
        console.log(result);

        for (i = 0; i < result.length; i++) {

            let user = result[i];

            console.log(user.userId + " " + user.userName + " " + user.pwd);
        }
        console.log('------------------------------------------------------------\n\n');
    }
})

function testSql()
{
    return new Promise((resolve, reject) => {
        // setTimeout(resolve, ms, 'done');
        setTimeout(reject, 1000, 'err');
    });
}

async function invTest()
{
    try {
        let t = await testSql();
        if (t)
        {
            console.log(t);
        }
    }
    catch (e) {
        console.log('await fail');
    }
}

invTest();

mysqlTool.executeSql ('INSERT INTO user(userName,registerTime,pwd) VALUES ("xlb4",now(),MD5(123456))',function (err,result) {

    if (err)
    {
        console.log(err.message);
    }
    else
    {
        console.log('--------------------------IINSERT----------------------------');
        console.log(result);
        console.log('------------------------------------------------------------\n\n');
    }
})

mysqlTool.executeSql ('UPDATE fileResource set status = 2 WHERE fileid = 1',function (err,result) {

    if (err)
    {
        console.log(err.message);
    }
    else
    {
        console.log('--------------------------UPDATE----------------------------');
        console.log(result);
        console.log('------------------------------------------------------------\n\n');
    }
})


mysqlTool.executeSql ('DELETE FROM user WHERE userName = "xlb4"',function (err,result) {

    if (err)
    {
        console.log(err.message);
    }
    else
    {
        console.log('--------------------------Delete----------------------------');
        console.log(result);
        console.log('------------------------------------------------------------\n\n');
    }
})
